package com.mego.weblink.database.dbmodel;

import com.mego.weblink.utils.LonLat;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;


@Entity
public class Lonlatlog {

    @Id(autoincrement = true)
    private Long id;
    private double lon = 0;
    private double lat = 0;
    private long time = 0;
    @Generated(hash = 1396017591)
    public Lonlatlog(Long id, double lon, double lat, long time) {
        this.id = id;
        this.lon = lon;
        this.lat = lat;
        this.time = time;
    }
    @Generated(hash = 707109007)
    public Lonlatlog() {
    }

    public Lonlatlog(double lon, double lat) {
        this.lon = lon;
        this.lat = lat;
        this.time = System.currentTimeMillis();
    }

    public Long getId() {
        return this.id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public double getLon() {
        return this.lon;
    }
    public void setLon(double lon) {
        this.lon = lon;
    }
    public double getLat() {
        return this.lat;
    }
    public void setLat(double lat) {
        this.lat = lat;
    }
    public long getTime() {
        return this.time;
    }
    public void setTime(long time) {
        this.time = time;
    }


    public String getLonlatStr() {
        SimpleDateFormat formatter = new SimpleDateFormat("HHmmss");
        Date curDate = new Date(time);
        String strDate = formatter.format(curDate);
        return strDate + "," + getLLstr();
    }

    private String getLLstr() {

        String strLat = "000000.0000";
        String strLon = "000000.0000";

        if (new LonLat(lon, lat).IsValid()) {
            String preLat = "N";
            if (lat < 0) {
                lat = -lat;
                preLat = "S";
            }
            int lat0 = (int)lat;
            double lat1 = (lat - lat0) * 60;
            strLat = preLat + new DecimalFormat("00.0000").format(lat0 * 100 + lat1);

            String preLon = "E";
            if (lon < 0) {
                lon = -lon;
                preLon = "W";
            }

            int lon0 = (int)lon;
            double lon1 = (lon - lon0) * 60;
            strLon = preLon + new DecimalFormat("00.0000").format(lon0 * 100 + lon1);
        }

        return strLat + "," + strLon;
    }


}
